#!/bin/bash

## 获取当前脚本名
script_name=$0
run_name=demo01_action_server

## 去除-前的字符和.后的字符
## colcon_build-cpp03_action.sh -> cpp03_action
script_name_start=$(echo "${script_name}" | awk -F"-" '{print $2}'|awk -F"." '{print $1}')

## 截取名字中，可执行文件的名字
if [ -z ${run_name} ]; then
    ### cpp03_action -> action
    exec_name=$(echo "${script_name_start}" | awk -F"_" '{print $2}'|awk -F"_" '{print $1}')
else
    exec_name=${run_name}
fi

#echo "cript_name_start=${cript_name_start}"
#echo "exec_name=${exec_name}"
#exit

echo ""
echo "[ Command ] colcon build --packages-select ${script_name_start}"
echo ""
colcon build --packages-select ${script_name_start}
echo ""
#
#echo "[ Command ] . install/setup.bash"
#. install/setup.bash
#
#echo "[ Command ] source install/setup.bash"
#source install/setup.bash
#
echo "[ Command ] bash install/setup.bash"
bash install/setup.bash

echo ""
echo "[ Info ] sleep 0.5"
sleep 0.5
echo ""
echo "------------------"
echo ""
echo "[ Command ] ros2 run ${script_name_start} ${exec_name}  "
echo ""
ros2 run ${script_name_start} ${exec_name}  
echo ""
